package com.by.client.factory;

import com.by.bean.PaymentMethod;
import com.by.client.PaymentClient;
import com.by.client.impl.AlipayPayClient;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Component
public class PaymentClientFactory {
    private final Map<PaymentMethod, PaymentClient> clients = new HashMap<>();

    public PaymentClientFactory(
//            WechatPayClient wechatPayClient,
            AlipayPayClient alipayPayClient
    ) {
//        clients.put(PaymentMethod.WECHAT, wechatPayClient);
        clients.put(PaymentMethod.ALIPAY, alipayPayClient);
    }

    public PaymentClient getClient(PaymentMethod method) {
        return Optional.ofNullable(clients.get(method))
                .orElseThrow(() -> new IllegalArgumentException("不支持的支付方式"));
    }
}